package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroGroupDao;
import com.ctg.itrdc.imageconsole.data.entity.DockerMicroGroup;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("dockerMicroGroupDao")
public class DockerMicroGroupDaoImpl extends BaseDaoImpl implements IDockerMicroGroupDao{

	@Override
	public Long insert(String tenantCode, String k8sCode, String groupCode) 
	{
		DockerMicroGroup group = new DockerMicroGroup();
		group.setTenantCode(tenantCode);
		group.setK8sCode(k8sCode);
		group.setGroupCode(groupCode);
		return super.insert(group);
	}	

	@Override
	public DockerMicroGroup selectByK8sCodeAndGroupCode(String k8sCode, String groupCode) 
	{
		DockerMicroGroup group = new DockerMicroGroup();		
		group.setK8sCode(k8sCode);
		group.setGroupCode(groupCode);		
		List<DockerMicroGroup> GroupList = super.selectByExample(group);		
		if(GroupList.size() > 1)
			throw new RuntimeException("Error : selecting Group returns " + GroupList.size() + " records, 0 or 1 desired");
		return GroupList.isEmpty() ? null : GroupList.get(0);
	}

	@Override
	public DockerMicroGroup selectById(Long id) 
	{
		DockerMicroGroup group = new DockerMicroGroup();
		group.setId(id);
		return super.selectByPrimaryKey(group);
	}

	@Override
	public void updateGroupCode(Long id, String groupCode) 
	{
		DockerMicroGroup group = new DockerMicroGroup();
		group.setId(id);
		group.setGroupCode(groupCode);
		super.updateSelectiveByPrimaryKey(group);
	}
	
	
}
